package com.wen.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wen.commonutils.ResultEntity;
import com.wen.edu.entity.EduCourse;
import com.wen.edu.entity.EduTeacher;
import com.wen.edu.service.EduCourseService;
import com.wen.edu.service.EduTeacherService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author：Win
 * @Date: 2021/6/16 10:23
 * @Description: 前端页面讲师分页显示
 */
@RestController
@RequestMapping("/edu/service/front/teacher")
public class FrontTeacherController {
    @Resource
    private EduTeacherService eduTeacherService;
    @Resource
    private EduCourseService eduCourseService;

    /**
     * 分页查询前台讲师数据
     *
     * @param page 当前页
     * @param size 每页显示数量
     * @return resultEntity
     */
    @PostMapping("pageFrontTeacher/{page}/{size}")
    public ResultEntity pageFrontTeacher(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        Page<EduTeacher> pageTeacher = new Page<>(page, size);
        Map<String, Object> map = eduTeacherService.pageFrontTeacher(pageTeacher);
        return ResultEntity.ok().data(map);
    }

    /**
     * 查询讲师信息
     *
     * @param teacherId 讲师id
     * @return result object
     */
    @GetMapping("getFrontTeacherInfo/{teacherId}")
    public ResultEntity getFrontTeacherInfo(@PathVariable("teacherId") String teacherId) {
//        根据讲师id查询讲师基本信息
        EduTeacher teacher = eduTeacherService.getById(teacherId);
//        根据讲师id查询课程信息
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id", teacherId);
        List<EduCourse> courseList = eduCourseService.list(wrapper);
        return ResultEntity.ok().data("teacher", teacher).data("courseList", courseList);
    }
}
